Introduction

Hardware-oriented stream ciphers are designed to be run on dedicated hardware. They typically work on the bit-level, since hardware can be custom-tailored to be more efficient with these operations. Almost all hardware stream ciphers are built upon a concept called feedback shift registers (FSRs).

Feedback Shift Registers

An FSR is comprised of a bit array, called a register, which is equipped with an update feedback function, denoted as , which takes a bit array and produces a single bit based on it. Each update alters the register and produces a single output bit. Given a current register state, , the subsequent state will be this:

The current state is left-shifted by a single position. The bit leaving the register is returned as the output for this update cycle and the bit in the end of the register is filled with . Here, | denotes the OR operation.

For example, suppose you had a feedback function, which simply XOR-ed all the bits of the register. Given an initial state, , you would have . The new state would thus be .

Given a feedback function and an initial state , we define the period of the FSR to be the number of updates that the FSR can go through until the new state repeats with one of the previous states, thus forming a cycle. Note, that the period of the FSR will be the same if we substituted for any other state which is produced during its cycle and any single state may only belong to a single cycle.

With the above function, , and state, , the period would be 6.

Naturally, an FSR with a larger period will produce a more unpredictable output.

Linear Feedback Shift Registers (LFSR)

Linear Feedback Shift Registers are FSRs which are equipped with a linear feedback function, namely a procedure which XORs together some of the bits of the current state. The bits that get XOR-ed together are defined by a set of boolean feedback coefficients. It is important that the feedback coefficients are not allowed to mutate throughout any update, since they define the feedback function. The number of bits in the bit array of the register is called its degree.

For a register consisting of bits and feedback coefficients , the state of the LFSR is updated by shifting the register to the right and replacing the left-most bit with the output of the feedback function. Namely, if the register state at time is described by , the state after an update (also called a clock tick) would be given by:

For each clock tick, the LFSR outputs the value of the right-most bit, . Thus, if the initial state of the LFSR is , then the first bits of the output stream will be the sequence , with the next output bit being .

The maximal period of an LFSR is , where is the degree of the LFSR, for the all-zeros state can never be mutated via a XOR operation. It is paramount that the correct feedback coefficients are chosen in order to ensure a maximal period. Luckily, there is a procedure for accomplishing just that. Starting from 1 for the left-most bit moving up to for the right-most bit, we construct a polynomial of the form , where the term is only included if the th bit has a feedback coefficient equal to 1 (it is included in the XOR operation). Now, the period is maximal if and only if this polynomial is primitive. A polynomial is primitive when it is irreducible (factorisation is impossible) and also satisfies additional mathematical criteria, which I unfortunately do not comprehend myself, but you can read more about them here.

LFSRs are inherently insecure due to their linearity. Given known feedback coefficients, the first output bits will reveal the initial state and from then on it is possible to determine the entirety of all future bits. Even with unknown feedback coefficients, an attacker needs at most output bits to determine both the feedback coefficients and the initial state. If we denote the first output bits as and the next bits as , we can construct the following system of linear equations:

It is possible to show that for a maximal period LFSR the equations in the system are linearly independent () and can be solved through basic linear algebra.

Introducing Nonlinearity

LFSRs can be strengthen by introducing nonlinearity in the encryption process by different means. This means that it is not only XOR operations that are used, but also logical ANDs and ORs. For example, it is possible to make the feedback loop nonlinear by setting the value of the leftmost bit at each clock tick to be a nonlinear function of the bits in the previous state. If the register's state at time is , the state at would be

As before, the rightmost bit, is outputted at each clock tick. In order for the FSR to be secure, the feedback function, should be balanced in the sense that .

Unfortunately, there is a downside to NFSRs (Nonlinear FSRs). There is no efficient way to determine an NFSR's period or even whether its period is maximal. It is however, possible to mitigate this by combining NFSRs and LFSRs, which is what Grain-128a does.

Filtered FSRs

In the above example, the FSR itself is nonlinear, since the way that the leftmost is altered at each clock tick is determined by a nonlinear function. However, it is also possible to keep the FSR linear and instead pass its output to a filter function, . Instead of outputting the rightmost bit, , the entire register is passed to the filter function and the output of the register is determined by the output of .

Whilst filtered FSRs are stronger than LFSRs, their underlying partial linearity makes them vulnerable to complex attacks such as algebraic attacks, cube attacks, and fast correlation attacks.